import { createRouter, createWebHistory } from 'vue-router'
import MainLayout from '@/layouts/MainLayout.vue'
import Home from '@/views/Home.vue'
import Login from '@/views/Login.vue'
import Register from '@/views/Register.vue'
import Entrance from '@/views/Entrance.vue'

// ✅ 引入 Pinia 和用户 Store
import { createPinia, setActivePinia } from 'pinia'
import { useUserStore } from '@/stores/userStore'

// ✅ 激活 Pinia，以便 setup 外调用 store
setActivePinia(createPinia())

const routes = [
  {
    path: '/',
    component: MainLayout,
    children: [
      { path: '', name: 'Home', component: Home },
      { path: 'brand', component: () => import('@/views/Brand.vue') },
      { path: 'products', component: () => import('@/views/Products.vue') },
      { path: 'stores', component: () => import('@/views/Stores.vue') },
      { path: 'news', component: () => import('@/views/News.vue') },
      { path: 'contact', component: () => import('@/views/Contact.vue') },
      {
        path: '/staff-chat',
        name: 'staff-chat',
        component: () => import('@/views/StaffChat.vue'),
        meta: { requiresAuth: true, role: 'staff' }
      }, {
        path: '/admin',
        component: () => import('@/views/admin.vue'),
        meta: {
          requiresAdmin: true,
          role: 'admin'
        }
      },
    ]
  },
  { path: '/login', component: Login },
  { path: '/register', component: Register },
  { path: '/entrance', component: Entrance },
  { path: '/profile', component: () => import('@/views/Profile.vue') },
  {
    path: '/news/all',
    name: 'AllNews',
    component: () => import('@/views/AllNews.vue')
  },
]

const router = createRouter({
  history: createWebHistory(),
  routes
})




export default router
